﻿CREATE PROCEDURE [acms].[SearchTerm_Put]
	@Term varchar(50), 
	@SiteId int,
	@IdOut int output,
	@CountOut int output
AS
	If Exists (Select null from SearchTerms with (nolock) Where Term = @Term and SiteId = @SiteId)
		Update SearchTerms
		Set
			Count = Count + 1
		Where Term = @Term and SiteId = @SiteId
	else
		Insert into SearchTerms
			(Term, SiteId, Count)
		Values
			(@Term, @SiteId, 1)
	Select @IdOut = Id, @CountOut = Count From SearchTerms Where Term = @Term and SiteId = @SiteId
RETURN 0;